package wql.boot.wqlspringboot02.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import wql.boot.wqlspringboot02.filter.WqlFilter;
import wql.boot.wqlspringboot02.servelt.WqlServelt;

import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.Servlet;
import javax.servlet.http.HttpServlet;

/**
 * @author wql
 * @version 1.0
 * @date 2022/11/16 15:37
 */
@Configuration
public class MyConfig {
    @Bean
    public ServletRegistrationBean<HttpServlet> registrationBean(){
        ServletRegistrationBean<HttpServlet> servletRegistrationBean = new ServletRegistrationBean<>();
        servletRegistrationBean.setName("my");
        servletRegistrationBean.addUrlMappings("/my");
        servletRegistrationBean.setServlet(new WqlServelt());
        return servletRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean<Filter> filterRegistrationBean(){
        FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setName("wqlfilter");
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setFilter(new WqlFilter());
        return filterRegistrationBean;
    }
}
